from scapy.all import IP, ICMP, sr1
from random import randint

def scapy_ping_one(host):
    # 随机生成 IP 和 ICMP 的 ID 和序列号
    id_ip = randint(1, 65535)
    id_ping = randint(1, 65535)
    seq_ping = randint(1, 65535)
    
    # 构造 ICMP 请求包
    packet = IP(dst=host, ttl=64, id=id_ip) / ICMP(id=id_ping, seq=seq_ping)
    
    # 发送包并接收响应
    response = sr1(packet, timeout=1, verbose=False)
    
    if response:
        print(f"[+] {host} is alive")
    else:
        print(f"[-] {host} is not responding")

# 示例：ping 一个 IP 地址
if __name__ == '__main__':
    target_ip = "192.168.1.1"
    scapy_ping_one(target_ip)